package com.cy.pj.notices.web.pojo;

/**
 * 所有的web项目，在设计响应数据时，都会有一个规范，比方说要响应给客户端什么数据，以什么格式进行响应。
 * 当前项目中，我们基于JsonResult对象封装服务端响应到客户端数据，
 * 对于这样的对象通常会包含三部分内容
 * 1)状态码
 * 2)消息
 * 3)数据
 */
public class JsonResult {//服务端响应到客户端的数据标准对象
    private Integer state=1;//状态码   1表示OK,0表示Exception
    private String message="OK";//状态信息
    private Object data; //响应数据,一般为查询操作结果

    public  JsonResult(){}
    public JsonResult(Integer state) {
        this.state = state;
    }

    public JsonResult(String message) {
        this.message = message;
    }

    public JsonResult(Object data) {
        this.data = data;
    }

    public JsonResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }

    public JsonResult(String message, Object data) {
        this.message = message;
        this.data = data;
    }

    public JsonResult(Integer state, Object data) {
        this.state = state;
        this.data = data;
    }

    public JsonResult(Integer state, String message, Object data) {
        this.state = state;
        this.message = message;
        this.data = data;
    }

    public JsonResult(Throwable e){//new JsonResult(exception);
        //this.state=0;
        //this.message=e.getMessage();
        this(0,e.getMessage());
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
